<?php
/**
 * Notes: 群聊模型
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/9/30
 * Time: 22:47
 */

namespace app\model;


use think\Model;

class GroupChat extends Model
{
    public function getMyCreateGroupChat($user_id){
        return self::where([
            'user_id' => $user_id
        ])->select();
    }

    public function add($data){
        return self::create($data);
    }

    public function del($group_chat_id){
        return self::get($group_chat_id)->delete();
    }

    public function edit($group_chat_id,$data){
        return self::allowField(true)->save($data,['group_chat_id' => $group_chat_id]);
    }

    public function check($group_chat_id){
        return self::where(['group_chat_id' => $group_chat_id]) -> count();
    }

    public function checkMy($group_chat_id,$user_id){
        return self::where([
            'group_chat_id' => $group_chat_id,
            'user_id' => $user_id
        ])->count();
    }
    public function groupchatlist(){
        return $this->belongsToMany('GroupChatList');
    }
    public function getById($group_chat_id){
        return self::get($group_chat_id);
    }
    public function checkNum($group_chat_id){
//        return
    }
    public function setNumIns($group_chat_id){
        return self::get($group_chat_id)->setInc('group_num',1);
    }
    public function setNumDec($group_chat_id){
        return self::get($group_chat_id)->setInc('group_num',1);
    }
    public function getStatus($value){
        $status = [ 1 => '正常' , 2 => '禁言'];
        return $status[$value];
    }

    public function checkMax($value){
        $max = [ 200 => "200人群" , 500 => "500人群" , 1000 => "1000人群"];
        return $max[$value];
    }



}